package com.nolf.learn.tree;

import java.util.LinkedList;
import java.util.Queue;

public class LevelOrderTraversal {

    public static void traverse(Node root, Visitor visit) {
        Queue<Node> q = new LinkedList<Node>();
        q.add(root);
        while (!q.isEmpty()) {
            Node n = q.poll();
            visit.execute(n);
            
            if (n.left != null) 
                q.add(n.left);
            
            if (n.right != null) 
                q.add(n.right);
        }
        
    }
}
